1572E - Polygon - CodeForces Solution


binary search dp geometry *3000

Please click on ads to support us..

C++ Code:

#include <iostream>
using namespace std;
const int N=205;
long long n,k,x[N],y[N];
pair<long long,long long> f[N][N];
long long area(long long i,long long j,long long k) {
  return (x[j]-x[i])*(y[k]-y[i])-(y[j]-y[i])*(x[k]-x[i]);
}
int main(){
  cin>>n>>k;
  for(int i=1;i<=n; i++) cin>>x[i]>>y[i];
  long long l=0,r=1e17;
  while(l<r){
    long long mid=(l+r+1)>>1;
    for(long long len=3;len<=n;len++){
      for(long long i=1,j=len;j<=n;i++,j++){
        f[i][j]={0,0};
        for(long long k=i+1;k<j;k++){
          long long a=f[i][k].first+f[k][j].first;
          long long b=f[i][k].second+f[k][j].second+area(i,k,j);
          f[i][j]=max(f[i][j],b>=mid?make_pair(a+1,0ll):make_pair(a,b));
        }
      }
    }
    f[1][n].first> k?l=mid:r=mid-1;
  }
  cout<<l<<endl;
  return 0;
}


Comments

Submit
0 Comments
More Questions

1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS